<? startScript('jquery, jquery.thumbdnd, swfobject, jquery.uploadify, img'); ?><script type="text/javascript">

jQuery(function($) {
					 
	$("#objects").thumbDnD({
	    onDragClass: "dragging",
	    onDrop: function(list, li) {
			$.post("sort-manual/", {order:$(list).thumbDnDSerialize()});
	    },
		dragHandle: ".dragHandle",
		serializeRegexp: /^obj-(.*)$/,
		serializeRegexpPos: 1,
	});
	
	$("#objects .thumb a.button").click(function() {
		var self = $(this), href = self.attr("href"), parent = self.parents(".thumb"), id = parent.attr("id").substr(4);

		if (self.hasClass('kill')) {
			if (confirm('Are you sure you want to kill this image?')) {
				$.post(href);
				parent.remove();
			}
			return false;
		}

		return true;
	});
	
	$('#uploader').uploadify({
		uploader		: '/lib/uploadify.swf',
		script		: 'upload-images/',
		cancelImg	: '/img/cancel.png',
		buttonText	: 'Select files', //	buttonText	: '<?=ht('Select files', 'cpn')?>',
		folder		: '/',
		fileDesc		: 'Image Files',
		fileExt		: '*.jpg;*.jpeg;*.gif;*.png;*.flv',
		multi			: true,
		auto			: true,
		scriptData	: { '<?=$SESSION_NAME?>': '<?=($t = session_id()).pwd($t)?>' },
		onAllComplete: function() { location.href = "." }
	});
	
});

</script><? endScript();

?><form action="" method="post" enctype="multipart/form-data">

		<div>
			<p><label><?=t('Add multiple images (size:', 'cpn')?> <?=talkImageSize($s['w'], $s['h'])?>)<br />
				<input type="file" name="file_upload" class="wide" id="uploader" />
			</label></p>
		</div>

</form><?

if (sizeof($d = dat('gallery'))) {

	?><style type="text/css">.thumb{height:<?=$s['tnh'] + 36?>px}</style><ul id="objects"><?

	foreach (dat('gallery') as $im => $info) { 

		?><li id="obj-<?=$im?>" class="thumb">
			<div class="toolbar">
			<a title='Edit image' class="button edit" href="edit-<?=$im?>/"><span>Edit</span></a>
				<a title='Kill image' class="button kill" href="delete-<?=$im?>/"><span>Kill</span></a>
				<div class="dragHandle"></div>
				<div class="clearer"></div>
			</div>
			<a href="#" title="See full picture in a window" onclick="return showImage('<?="$s[path]$im"?>', '', <?=$info['w']?>, <?=$info['h']?>);">
				<img src="<?="$s[path]$info[tn]"?>" />
			</a>
			<div class="fn"><?=$im?></div>
		</li><?
	}

?><div class="clearer"></div></ul>

<form action="" method="post" enctype="multipart/form-data">

		<div>
			<p><label><?=t('Add image (size:', 'cpn')?> <?=talkImageSize($s['w'], $s['h'])?>)<br />
				<input type="file" name="image" class="wide" />
			</label></p>
			<p><input type="submit" name="photo_add" value="Add" /></p>
		</div>

</form><?

}